export default {
    data() {
        return {
            throttling: '', // 节流
            isDisable: false, // 获取验证码按钮状态
            VerificationInfo: "获取验证码",
        }
    },
    methods: {
        // 表单校验
        formValidate(foemName, callback) {
            this.$refs[foemName].validate((valid) => {
                if (valid) {
                    if (this.throttling && (Date.now() - this.throttling < 1500)) return this.$message.warning('请勿重复操作');
                    callback();
                    this.throttling = Date.now();
                    ////console.log('发送成功');
                } else {
                    return false;
                }
            });
        },
        // 验证码定时器
        VerificationTime() {
            var time = 59;
            var Interval = setInterval(() => {
                this.VerificationInfo = time-- + "S后可重发";
                if (time <= 0) {
                    clearInterval(Interval);
                    this.VerificationInfo = "获取验证码";
                    this.isDisable = false;
                }
            }, 1000);
        },
        // 键盘事件
        keydown(e) {
            if (e.key !== "Enter") return;
            this.formValidate(this.ref, this.login);
        },
    },
}